GBML manual / Tweens

ease

Bends a plain 0-to-1 progress into one of the tween curves: ease(0.5, EASE_QUAD_IN) is a number below 0.5, because that curve starts slowly. Use it to ease something you move yourself, such as a menu that slides in or a bar that fills, when you already keep the progress in a variable.

Syntax

ease(t, curve) -> real

Arguments

NameType
treal
curveeasing

Returns

real

Description

Bends a plain 0-to-1 progress into one of the sixteen easing curves. t is how far along you are: 0 at the start, 1 at the end. The answer is how far along the curve is at that moment, also 0 at the start and 1 at the end. ease(0.5, EASE_QUAD_IN) is 0.25, a number below 0.5, because that curve starts slowly.

Use it when you already keep the progress yourself, for a menu that slides in or a bar that fills, and just want it to feel better than a straight line.

Example

var t = 0.5;
var shaped = ease(t, EASE_QUAD_OUT);
x = lerp(20, 200, shaped);

shaped is 0.75: the curve starts fast, so half the time has covered three quarters of the way. lerp turns that 0-to-1 into a real place between 20 and 200.

ease or tween?

tween does the timing for you: you say a start frame and how long, and it works out the progress from the game's frame counter. ease has no clock. You give it the progress, so it fits anything that has a 0-to-1 number of its own: a health bar, inverse_lerp of a distance, a slider the player moves.

The small print

Cost

A few whole-number sums; the sine curves use the sine table. Cheap enough for every frame.

On the GBA

The same sixteen curves tween uses, from the same table-free arithmetic. t is how far along you are, 0 at the start and 1 at the end: a t below 0 counts as 0 and a t above 1 as 1, so the answer for each end is exactly 0 and exactly 1. Most curves stay between 0 and 1; EASE_BACK_ and EASE_ELASTIC_ go past them on purpose for a moment (see tween), so do not use those on something that must stay in a range. To turn the 0-to-1 into a real distance, use lerp: x = lerp(from, to, ease(t, EASE_SINE_OUT)). tween does the timing for you from a start frame; ease only bends the number you give it.

See also: tweenTweenslerpinverse_lerpEASE_LINEAREASE_QUAD_OUT